home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Macintosh Sample Code / SC.023.FracApp 2.0 / UOffscreen.p < prev    next >
Encoding:
Text File  |  1990-04-30  |  8.0 KB  |  208 lines  |  [TEXT/MPS ]

  1. {[j=20/53/1$] Pasmat Options}
  2.  
  3. UNIT UOffscreen;
  4.  
  5. {-------------------------------------------------------------------------------------------
  6.  
  7.     Program:    FracApp 2.0
  8.     Unit:        UOffscreen
  9.     Files:        UOffscreen.p
  10.     Includes:    UOffscreen.inc1.p
  11.  
  12.     by Keith Rollin & Bo3b Johnson
  13.     of Apple Macintosh Developer Technical Support
  14.  
  15.     Copyright © 1989-1990 Apple Computer, Inc.
  16.     All rights reserved.
  17.  
  18. --------------------------------------------------------------------------------------------
  19.  
  20.     Offscreen management. Herein, we have three objects. There is a TOffscreen
  21.     object, that defines some common routines and method names. It really doesn’t
  22.     do a whole lot, as    most of the functionality is implemented in its
  23.     sub-classes: TOldGrossOffscreen, and TNewCoolOffscreen.
  24.  
  25.     TOldGrossOffscreen is a set of home brew routines that implement offscreen
  26.     PixMaps totally by hand. These are the routines that are in the original
  27.     version of FracApp. In the past, this was the only way to create offscreen
  28.     PixMaps.When initializing TOldGrossOffscreen, we create a new PixMap and data
  29.     buffer, set up all the values for them, clear the buffer, create a gDevice
  30.     record, initialize it, attach the two together, and hope that it will still
  31.     work under new Systems. TNewCoolOffscreen uses the new 32-Bit Color QuickDraw
  32.     routines if they are available. It just calls NewGWorld, and attaches our color
  33.     table to it.
  34.  
  35.     There are several support routines for TOffscreens. ChangeCTFlag is used to set
  36.     or clear color table flags. This was hacked in to support the need to clear and
  37.     set bit 14 when we save the PixMap to disk. LockThePixels and UnlockThePixels
  38.     is called whenever we have to perform some QuickDraw operation, like CopyBits.
  39.     This is only needed for the TNewCoolOffscreen stuff, and is a null operation
  40.     uner TOldGrossOffscreen. SaveOldWorld and SetupOffWorld are used for saving
  41.     whatever port and gDevice are set, and swapping in the offscreen drawing
  42.     environment. RestoreOffWorld is called when we are done to reverse the effects
  43.     of SetupOffWorld. None of these last 5 routines (LockThePixels,
  44.     UnlockThePixels, SaveOldWorld, SetupOffWorld, RestoreOffWorld) should be called
  45.     directly, as they are combined in the PreDraw and PostDraw routines, which take
  46.     care of all the management. Whenever you need to do offscreen drawing, call
  47.     PreDraw, and then PostDraw when you are done. Finally, if you need to get the
  48.     offscreen port for some direct manipulation (like for CopyBits), call
  49.     GetOffPort.
  50.  
  51. --------------------------------------------------------------------------------------------}
  52.  
  53.     INTERFACE
  54.  
  55.         USES UMacApp, QDOffScreen;
  56.  
  57.         CONST
  58.  
  59.             kAnimationFlag        = 14;
  60.             kClearFlag            = FALSE;
  61.             kSetFlag            = TRUE;
  62.  
  63.         TYPE
  64.  
  65.             TOffscreen            = OBJECT (TObject)
  66.  
  67.                 fOldDevice:         GDHandle;        { Holds the previous device while we’re
  68.                                                      busy playing in the offscreen world.
  69.                                                      You can fetch the device if you need to
  70.                                                      with GetOldDevice. }
  71.                 fOldPort:            GrafPtr;        { Holds the previous GrafPort while we’re
  72.                                                      busy playing in the offscreen world.
  73.                                                      You can fetch the port if you need to
  74.                                                      with GetOldPort. }
  75.                 PROCEDURE TOffscreen.IOffscreen;
  76.                 { Initialize the offscreen world. }
  77.  
  78.                 PROCEDURE TOffscreen.ChangeCTFlag(whichBit: Integer; whichWay: Boolean);
  79.                 { Set or clear a color table flag. }
  80.  
  81.                 FUNCTION TOffscreen.GetOffDevice: GDHandle;
  82.                 { Return the GDHandle of the device belonging to the offscreen port. Must be
  83.                   overridden. }
  84.  
  85.                 FUNCTION TOffscreen.GetOffPixBase: Ptr;
  86.                 { Return the base address of our offscreen pixels. Must be overridden. }
  87.  
  88.                 FUNCTION TOffscreen.GetOffPort: CGrafPtr;
  89.                 { Return a CGrafPtr to the offscreen port. Must be overridden. }
  90.  
  91.                 FUNCTION TOffscreen.GetOldDevice: GDHandle;
  92.                 { Return a GDHandle to the saved device. }
  93.  
  94.                 FUNCTION TOffscreen.GetOldPort: GrafPtr;
  95.                 { Return a GrafPtr to the saved port. }
  96.  
  97.                 PROCEDURE TOffscreen.LockThePixels;
  98.                 { For 32BCQD support. Does nothing by default. }
  99.  
  100.                 PROCEDURE TOffscreen.PreDraw;
  101.                 { Call this method to save off the current drawing world and swap in the
  102.                   offscreen drawing world. }
  103.  
  104.                 PROCEDURE TOffscreen.PostDraw;
  105.                 { Call this method to restore the drawing world saved by PreDraw. }
  106.  
  107.                 PROCEDURE TOffscreen.RestoreOldWorld;
  108.                 { Called by PostDraw to restore the old port and gDevice. Should not need
  109.                   to be called directly. PostDraw will call this for you. }
  110.  
  111.                 PROCEDURE TOffscreen.SaveOldWorld;
  112.                 { Called by PreDraw to save the old port and gDevice. Should not need
  113.                   to be called directly. PreDraw will call this for you.  }
  114.  
  115.                 PROCEDURE TOffscreen.SetupOffWorld;
  116.                 { Called by PreDraw to set the offscreen port and gDevice. Must be overridden.
  117.                   }
  118.  
  119.                 PROCEDURE TOffscreen.UnlockThePixels;
  120.                 { For 32BCQD support. Does nothing by default. }
  121.  
  122.                 PROCEDURE TOffscreen.Fields(PROCEDURE
  123.                                             DoToField(fieldName: Str255; fieldAddr: Ptr;
  124.                                                       fieldType: Integer)); OVERRIDE;
  125.  
  126.                 END;
  127.  
  128.             TOldGrossOffscreen    = OBJECT (TOffscreen)
  129.  
  130.                 fBigBuff:            Ptr;            { The memory to use for our pixels in the
  131.                                                      offscreen world. You can get their
  132.                                                      address with GetOffPixBase. }
  133.                 fOffDevice:         GDHandle;        { Holds the offscreen device to use when
  134.                                                      playing with the offscreen world. You
  135.                                                      can fetch the device if you need to
  136.                                                      with GetOffDevice. }
  137.                 fOffPort:            CGrafPtr;        { Holds the offscreen GrafPort to use
  138.                                                      when playing with the offscreen world.
  139.                                                      You can fetch the port if you need to
  140.                                                      with GetOffPort. }
  141.  
  142.                 PROCEDURE TOldGrossOffscreen.IOldGrossOffscreen(offBounds: Rect;
  143.                                                                 itsColors: CTabHandle);
  144.                 { Create and initialize an offscreen drawing environment using the routines
  145.                   described in Inside Mac V. The offscreen world size is specified by
  146.                   “offBound”, and uses the colors in itsColors. It makes a copy of the
  147.                   table. }
  148.  
  149.                 PROCEDURE TOldGrossOffscreen.Free; OVERRIDE;
  150.  
  151.                 FUNCTION TOldGrossOffscreen.GetOffDevice: GDHandle; OVERRIDE;
  152.                 FUNCTION TOldGrossOffscreen.GetOffPixBase: Ptr; OVERRIDE;
  153.                 FUNCTION TOldGrossOffscreen.GetOffPort: CGrafPtr; OVERRIDE;
  154.  
  155.                 PROCEDURE TOldGrossOffscreen.SetupOffWorld; OVERRIDE;
  156.                 { The default SetupOffWorld doesn’t do anything because it doesn’t know what
  157.                   form our offscreen management takes. So we have to override it here. }
  158.  
  159.                 PROCEDURE TOldGrossOffscreen.Fields(PROCEDURE
  160.                                                     DoToField(fieldName: Str255;
  161.                                                               fieldAddr: Ptr;
  162.                                                               fieldType: Integer)); OVERRIDE
  163.                     ;
  164.  
  165.                 END;
  166.  
  167.             TNewCoolOffscreen    = OBJECT (TOffscreen)
  168.  
  169.                 fOffWorld:            GWorldPtr;
  170.  
  171.                 PROCEDURE TNewCoolOffscreen.INewCoolOffscreen(offBounds: Rect;
  172.                                                               itsColors: CTabHandle);
  173.                 { Create and initialize an offscreen drawing environment using the 32-bit Color
  174.                   QuickDraw routines. The offscreen world size is specified by “offBound”, and
  175.                   uses the colors in itsColors. It makes a copy of the table. }
  176.  
  177.                 PROCEDURE TNewCoolOffscreen.Free; OVERRIDE;
  178.  
  179.                 FUNCTION TNewCoolOffscreen.GetOffDevice: GDHandle; OVERRIDE;
  180.                 FUNCTION TNewCoolOffscreen.GetOffPixBase: Ptr; OVERRIDE;
  181.                 FUNCTION TNewCoolOffscreen.GetOffPort: CGrafPtr; OVERRIDE;
  182.  
  183.                 PROCEDURE TNewCoolOffscreen.LockThePixels; OVERRIDE;
  184.  
  185.                 PROCEDURE TNewCoolOffscreen.PostDraw; OVERRIDE;
  186.                 { The base PostDraw will set the port and gDevice correctly. However, before it
  187.                   does that, we have to make sure that we unlock our offscreen bit so that the
  188.                   can float around and not fragment our heap. }
  189.  
  190.                 PROCEDURE TNewCoolOffscreen.SetupOffWorld; OVERRIDE;
  191.                 { The default SetupOffWorld doesn’t do anything because it doesn’t know what
  192.                   form our offscreen management takes. So we have to override it here. }
  193.  
  194.                 PROCEDURE TNewCoolOffscreen.UnlockThePixels; OVERRIDE;
  195.  
  196.                 PROCEDURE TNewCoolOffscreen.Fields(PROCEDURE
  197.                                                    DoToField(fieldName: Str255;
  198.                                                              fieldAddr: Ptr;
  199.                                                              fieldType: Integer)); OVERRIDE;
  200.  
  201.                 END;
  202.  
  203.     IMPLEMENTATION
  204.  
  205.         {$I UOffscreen.inc1.p}
  206.  
  207. END.
  208.